#!/bin/bash

echo "开始构建YOLOv8材料检测项目..."

# 检查依赖
echo "检查依赖库..."
if ! pkg-config --exists opencv4; then
    echo "错误: 未找到OpenCV4，请先安装OpenCV"
    exit 1
fi

# 创建构建目录
if [ ! -d "build" ]; then
    mkdir build
fi

cd build

# 配置项目
echo "配置项目..."
cmake .. -DCMAKE_BUILD_TYPE=Release

if [ $? -ne 0 ]; then
    echo "错误: CMake配置失败"
    exit 1
fi

# 编译项目
echo "编译项目..."
make -j$(nproc)

if [ $? -ne 0 ]; then
    echo "错误: 编译失败"
    exit 1
fi

echo "构建完成！"
echo "可执行文件位置:"
echo "  - camera_detect: ./build/camera_detect"
echo "  - test_yolov8: ./build/test_yolov8"

# 检查可执行文件
if [ -f "camera_detect" ]; then
    echo "✓ camera_detect 构建成功"
else
    echo "✗ camera_detect 构建失败"
fi

if [ -f "test_yolov8" ]; then
    echo "✓ test_yolov8 构建成功"
else
    echo "✗ test_yolov8 构建失败"
fi

echo ""
echo "使用方法:"
echo "  ./camera_detect [模型文件] [摄像头ID]"
echo "  ./test_yolov8" 